﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class export_testQuestionsExport : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string course_id = "";
        string test_question_name = "";

        System.Data.DataTable table1 = new System.Data.DataTable();
        int count = 0;//总记录的条数
        try
        {
            
            if (Request.QueryString["course_id"] != null)
            {
                course_id = Request.QueryString["course_id"].ToString().Trim();
            }
            if (Request.QueryString["test_question_name"] != null)
            {
                test_question_name = Request.QueryString["test_question_name"].ToString().Trim();
            }

            
            List<string> wheres = new List<string>();

            if (course_id != "")
            {
                wheres.Add("course_id like '%" + course_id + "%'");
            }
            if (test_question_name != "")
            {
                wheres.Add("test_question_name like '%" + test_question_name + "%'");
            }
            string wh = "";
            if (wheres.Count > 0)
            {
                wh = string.Join(" and ", wheres.ToArray());
                
            }
            
            
            string sql = "select test_question_id" +
                                    "      ,test_question_name" +
                                    "      ,test_score" +
                                    "      ,test_difficulty_level" +
                                    "      ,course_id" +
                                    "      ,radio_questions_sum" +
                                    "      ,mutil_questions_sum" +
                                    "      ,judge_questions_sum" +
                                    "      ,answer_questions_sum" +
                                    "  FROM dbo.tb_test_questions ";
            if (wheres.Count > 0)
            {
                sql = sql + " where " + wh ;
            }
           
            table1 = SqlServer.GetDataTable(sql);
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('有错误')</script>");
            Response.End();
        }
        Response.Write(Json.ToJson(table1, count));
        Response.End();
    }
}